#!/usr/bin/env python

# Description:
# Create thumbnail image for openraster image files.
#
# References:
# http://www.davidrevoy.com/article82/krita-kra-file-thumbnailer-for-gnome-nautilus-linux
# http://library.gnome.org/devel/integration-guide/stable/thumbnailer.html.en
# http://create.freedesktop.org/wiki/OpenRaster/File_Layout_Specification

import sys, zipfile, Image, StringIO

if len(sys.argv) != 4:
  sys.exit('Usage: '+sys.argv[0]+' <Input> <Output> <Size>')

f_in = sys.argv[1]
f_out = sys.argv[2]
thumb_size = int(sys.argv[3])

thumbnail = zipfile.ZipFile(f_in).read('Thumbnails/thumbnail.png')

im = Image.open(StringIO.StringIO(thumbnail))
im.thumbnail((thumb_size, thumb_size))

im.save(f_out,'png')
